## vim:ft=zsh
## perforce support by: Phil Pennock
## Distributed under the same BSD-ish license as zsh itself.

# XXX: This soooo needs to be cached
setopt localoptions extendedglob
local a b
local change changed
local action merging
local -A fsinfo
local -xA hook_com

${vcs_comm[cmd]} status | while IFS=: read a b; do fsinfo[${a//-/_}]="${b## #}"; done
fshash=${fsinfo[checkout]%% *}
changed=${(Mk)fsinfo:#(ADDED|EDITED|DELETED|UPDATED)*}
merging=${(Mk)fsinfo:#*_BY_MERGE*}
if [ -n "$merging" ]; then
   action="merging"
fi

# Build the revision display
zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" fsrevformat revformat || revformat="%.10h"

hook_com=( "hash" "${fshash}" )

if VCS_INFO_hook 'set-fsrev-format' "${revformat}"; then
    zformat -f fsrev "${revformat}" "h:${hook_com[hash]}"
else
    fsrev=${hook_com[rev-replace]}
fi

hook_com=()

# Now build the branch display
zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" branchformat fsbranch || fsbranch="%b:%r"

hook_com=( branch "${fsinfo[tags]%%, *}" revision "${fsrev}" )

if VCS_INFO_hook 'set-branch-format' "${fsbranch}"; then
    zformat -f fsbranch "${fsbranch}" "b:${hook_com[branch]}" "r:${hook_com[revision]}"
else
    fsbranch=${hook_com[branch-replace]}
fi

hook_com=()

VCS_INFO_formats "$action" "${fsbranch}" "${fsinfo[local_root]}" '' "$changed" "${fsrev}" "${fsinfo[repository]}"
return 0
